package com.zrwl.poscloud.xo.service.impl;
import com.zrwl.poscloud.base.entity.UserServiceConfig;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zrwl.poscloud.base.enums.EStatus;
import com.zrwl.poscloud.base.superI.SuperServiceImpl;
import com.zrwl.poscloud.commons.utils.ResultUtil;
import com.zrwl.poscloud.commons.utils.StringUtils;
import com.zrwl.poscloud.xo.global.MessageConf;
import com.zrwl.poscloud.xo.global.SQLConf;
import com.zrwl.poscloud.xo.global.SysConf;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;
import com.zrwl.poscloud.xo.mapper.UserServiceConfigMapper;
import com.zrwl.poscloud.xo.service.UserServiceConfigService;
import com.zrwl.poscloud.xo.vo.UserServiceConfigVO;

import javax.annotation.Resource;

/**
 * 产品配置 服务实现类
 *
 * @author 刘思童 AutoGenerate
 * @date 2023-05-23
 */
@Service
public class UserServiceConfigServiceImpl extends SuperServiceImpl<UserServiceConfigMapper,UserServiceConfig> implements UserServiceConfigService {

    @Autowired
    private UserServiceConfigService userServiceConfigService;

    @Resource
    private UserServiceConfigMapper userServiceConfigMapper;
    @Override
    public IPage<UserServiceConfig> getPageList(UserServiceConfigVO userServiceConfigVO){
       QueryWrapper<UserServiceConfig> queryWrapper = new QueryWrapper<>();
       if (StringUtils.isNotEmpty(userServiceConfigVO.getKeyword()) && !StringUtils.isEmpty(userServiceConfigVO.getKeyword().trim())) {
            queryWrapper.like("name", userServiceConfigVO.getKeyword().trim());
       }
       Page<UserServiceConfig> page = new Page<>();
       page.setCurrent(userServiceConfigVO.getCurrentPage());
       page.setSize(userServiceConfigVO.getPageSize());
       queryWrapper.ne(SQLConf.STATUS, EStatus.DISABLED);
       queryWrapper.orderByDesc(SQLConf.CREATE_TIME);
       IPage<UserServiceConfig> pageList = userServiceConfigService.page(page, queryWrapper);
       List<UserServiceConfig> list = pageList.getRecords();
       pageList.setRecords(list);
       return pageList;
}
    @Override
    public List<UserServiceConfig> getAllList(UserServiceConfigVO userServiceConfigVO){
        QueryWrapper<UserServiceConfig> queryWrapper = new QueryWrapper<>();
        queryWrapper.ne(SQLConf.STATUS, EStatus.DISABLED);
        queryWrapper.orderByAsc(SQLConf.CREATE_TIME);
        List<UserServiceConfig> list = userServiceConfigService.list(queryWrapper);
        return list;
}
    @Override
    public String add(UserServiceConfigVO userServiceConfigVO){
        UserServiceConfig entity = new UserServiceConfig();
        BeanUtils.copyProperties(userServiceConfigVO, entity, SysConf.STATUS);
        entity.insert();
        userServiceConfigVO.setUid(entity.getUid());
        return ResultUtil.successWithMessage(MessageConf.INSERT_SUCCESS);}
    @Override
    public String edit(UserServiceConfigVO userServiceConfigVO){
        UserServiceConfig entity = userServiceConfigService.getById(userServiceConfigVO.getUid());
        BeanUtils.copyProperties(userServiceConfigVO, entity);
        entity.updateById();
        return ResultUtil.successWithMessage(MessageConf.UPDATE_SUCCESS);
}
    @Override
    public String delete(UserServiceConfigVO userServiceConfigVO){
        UserServiceConfig entity = userServiceConfigService.getById(userServiceConfigVO.getUid());
        entity.setStatus(EStatus.DISABLED);
        entity.updateById();
        return ResultUtil.successWithMessage(MessageConf.UPDATE_SUCCESS);
}

    @Override
    public List<UserServiceConfigVO> getServiceConfigList(UserServiceConfigVO userServiceConfigVO) {
        return userServiceConfigMapper.getServiceConfigList(userServiceConfigVO);
    }
}
